package com.cooldatasoft.web.cms.common;
/**
 * 
 * @author fatih mehmet ucar
 *
 */
import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;

import com.cooldatasoft.app.WOCApplication;
import com.cooldatasoft.app.WOCSession;
import com.cooldatasoft.data.User;
import com.cooldatasoft.web.cms.user.UserListPage;
import com.cooldatasoft.web.cms.user.UserViewPage;

public class UserEditPanel extends Panel {

	public UserEditPanel(String id, IModel model, final FeedbackPanel feedbackPanel) {
		super(id, model);
		Link editLink = new Link("edit") {
			public void onClick() {
				Integer entityId = ((User)getParent().getModelObject()).getId();				
				setResponsePage(new UserViewPage(entityId));
			}
		};
		add(editLink);
		
		Link deleteLink=new Link("delete") {
			public void onClick() {				
				//Get selected object id
				Integer entityId = ((User)getParent().getModelObject()).getId();
				if(entityId != null && entityId == 1){
					feedbackPanel.error("Cannot delete admin user!");
					return;
				}
				WOCApplication.get().getUserServiceProxy().deleteUserById(entityId,((WOCSession)WOCSession.get()).getUser());
				setResponsePage(UserListPage.class);
			}
		};
		deleteLink.add( new SimpleAttributeModifier("onclick", "return confirm('Do you want to delete this record?');"));
		add(deleteLink);
	}
	

}
